<template>
    <div>
        <div >
            <i-table border :columns="columns" :data="tableData" :loading="loading"></i-table>
        </div>
        <div style="text-align: center;margin: 15px;">
            <Page :total="params.totalElements" :page-size="params.size" @on-change="changePage" show-total></Page>
        </div>
    </div>
</template>

<script>
    module.exports = {
        props:[],
        components: {
        },
        data() {
            return {
                columns: [
                    {
                        type: 'index',
                        width:40,
                        align: 'center'
                    },
                    {
                        title: '标题',
                        key: 'title',
                        align: 'center'
                    },
                    {
                        title: '发表人',
                        key: 'userNickName',
                        align: 'center'
                    },
                    {
                        title: '手机号',
                        key: 'mobile',
                        align: 'center'
                    },
                    {
                        title: '邮箱',
                        key: 'email',
                        align: 'center'
                    },
                    {
                        title: '地点',
                        key: 'address',
                        align: 'center'
                    },
                    {
                        title: '来源',
                        key: 'source',
                        align: 'center'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {
                            let btns = [];

                            btns.push(
                                h('Button', {
                                    props: {
                                        type: 'info',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '8px'
                                    },
                                    on: {
                                        click: () => {
                                            this.edit(params.index)
                                        }
                                    }
                                }, '修改')
                            )
                            btns.push(
                                h('Button', {
                                    props: {
                                        type: 'info',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '8px'
                                    },
                                    on: {
                                        click: () => {
                                            this.del(params.index)
                                        }
                                    }
                                }, '删除')
                            )
                            return h('div', btns);
                        }
                    }
                ],
                tableData:[],
                params:{
                    name:undefined,
                    page:0,
                    size:10,
                    totalElements:0,
                },
            }
        },
        mounted() {
            console.info("添加数据组件加载成功",this.show)

        },
        methods:{
            close(){
                this.show=false;
                this.$emit("close",this.show);
            },
            load() {
                console.info("table load")
                let _this = this;
                _this.loading=true;
                iget('/admin/news2',this.params,
                    successRes => {
                        _this.tableData=successRes.data.content
                        console.info("columns 数据 load 完毕！",_this.tableData)
                        _this.loading=false;
                    },failureRes => {
                        console.info("加载数据异常",failureRes)
                    }
                )
            },

            del(index){
                console.info("删除：",index)
            },
            edit(index){
                console.info("修改：",index)
            },
        }
    }
</script>
